//var vid;
function initLoading() {
	DWREngine.setPreHook(function () {
		loading();
	});
	DWREngine.setPostHook(function () {
		remove_loadingdiv();
	});
}
function loading() {
	show_loadingpage();
}
var div_left = 0;
var div_right = 0;
var loading_constant = 0;
function move_loading() {
	var move_div = document.getElementById("move_div");
	var move_div_arry = new Array();
	move_div_arry[1] = document.getElementById("move_div1");
	move_div_arry[2] = document.getElementById("move_div2");
	move_div_arry[3] = document.getElementById("move_div3");
	move_div_arry[4] = document.getElementById("move_div4");
	move_div_arry[5] = document.getElementById("move_div5");
	if (div_left < 250) {
		move_div.style.left = div_left + "px";
		div_left += 5;
		div_right = 250;
	} else {
		if (div_right > -77) {
			for (i = 1; i < 6; i++) {
				move_div_arry[i].className = "move_div" + (6 - i);
			}
			move_div.style.left = div_right + "px";
			div_right -= 4;
		} else {
			div_left = -77;
			for (i = 1; i < 6; i++) {
				move_div_arry[i].className = "move_div" + i;
			}
		}
	}
}
function flicker_text() {
	var loading_text = document.getElementById("loading_text");
	if (loading_constant == 0) {
		loading_text.style.color = "#4e7f31";
		loading_constant = 1;
	} else {
		loading_text.style.color = "#000000";
		loading_constant = 0;
	}
}
function show_loadingpage() {
	var cover_div = document.createElement("div");
	cover_div.id = "cover_divone";
	cover_div.style.height = "100%";
	cover_div.style.width = "100%";
	cover_div.style.position = "absolute";
	cover_div.style.left = "0";
	cover_div.style.top = "0";
	cover_div.style.zIndex = "3000";
	cover_div.innerHTML = "<iframe scrolling=\"no\" frameborder=\"0\" width=\"100%\" height=\"100%\" style=\"z-index:3000;\"></iframe>";
	cover_div.style.filter = "alpha(opacity=1)";
	cover_div.style.opacity = "0.1";
	var cover_div2 = document.createElement("div");
	cover_div2.id = "cover_divtwo";
	cover_div2.style.height = "100%";
	cover_div2.style.width = "100%";
	cover_div2.style.position = "absolute";
	cover_div2.style.left = "0";
	cover_div2.style.top = "0";
	cover_div2.style.zIndex = "3010";
	cover_div2.style.background = "#ffffff";
	cover_div2.style.filter = "alpha(opacity=3)";
	cover_div2.style.opacity = "0.3";
	var load_div = document.createElement("div");
	load_div.id = "load_div";
	load_div.style.height = "100%";
	load_div.style.width = "100%";
	load_div.style.position = "absolute";
	load_div.style.left = "0";
	load_div.style.top = "0";
	load_div.style.zIndex = "3100";	
	//load_div.style.textAlign='center';
	load_div.style.paddingTop = document.body.offsetHeight / 2 - 50 + "px";
	load_div.style.paddingLeft = document.body.offsetWidth / 2 - 100 + "px";
	document.body.appendChild(cover_div);
	document.body.appendChild(cover_div2);
	document.body.appendChild(load_div);
	load_div.innerHTML = "<div class=\"border_div\" id=\"border_div\"><div id=\"move_div\"><div class=\"move_div5\" id=\"move_div5\"></div><div class=\"move_div4\" id=\"move_div4\"></div><div class=\"move_div3\" id=\"move_div3\"></div><div class=\"move_div2\" id=\"move_div2\"></div><div class=\"move_div1\" id=\"move_div1\"></div></div></div><p id=\"loading_text\" style=\"margin:0 0 0 80px \">\u6b63\u5728\u52a0\u8f7d\u6570\u636e\uff0c\u8bf7\u7a0d\u5019......</p>";
	interv1 = setInterval("move_loading()", 50);
	interv2 = setInterval(flicker_text, 500);
}
function remove_loadingdiv() {
	if (window.interv1) {
		clearInterval(window.interv1);
	}
	if (window.interv2) {
		clearInterval(window.interv2);
	}
	var cover_divone = document.getElementById("cover_divone");
	var cover_divtwo = document.getElementById("cover_divtwo");
	var load_div = document.getElementById("load_div");
	document.body.removeChild(cover_divone);
	document.body.removeChild(cover_divtwo);
	document.body.removeChild(load_div);
}
function init() {
	initLoading();
	DWREngine.setTimeout(5000);
}


//DIV Creat
function creatDiv() {
	var rt_div = document.getElementById("rt_div");
	if (!rt_div) {
		var box = document.createElement("rt_div");
		box.id = "rt_div";
		box.style.position = "absolute";
		box.style.width = "700px";
		box.style.height = "400px";
		box.style.overflow = "visible";
		box.style.background="#ffffff";
		box.style.left =(document.body.offsetWidth-700)/2+"px";
		box.style.top =(document.body.offsetHeight-400)/2+"px";
		box.style.zIndex="10000";
		document.body.appendChild(box);
		//init_RtDiv();
		//box.innerHTML="<a onclick='close_rt_Div()'>aaaaa</a>";
	}
}
function close_rt_Div() {
	//var rt_div = document.getElementById("rt_div");
	//if (null != rt_div) {
	//	document.body.removeChild(rt_div);
	//}
	closelistDiv('plmb');
}
function init_PubRtDiv(obj) {
	init();
	//close_rt_Div();
	//creatDiv();
	//creat_RtDiv_table();
	creat_RtDiv_Pubhead(obj);
}
function init_PriDiv(obj) {
	init();
	//close_rt_Div();
	//creatDiv();
	//creat_RtDiv_table();
	creat_RtDiv_Prihead(obj);
}
function getRadioSelected(type, obj) {
	if ("pub" == type) {
		init_PubRtDiv(obj);
	} else {
		init_PriDiv(obj);
	}
}
function creat_RtDiv_table() {
	
}
function creat_RtDiv_Pubhead(obj) {
	//var rthead = document.getElementById("rt_table");
	var rtdiv = document.getElementById("rt_div");
	if ("add" == obj) {
		rtdiv.innerHTML = "<table id='s' width='100%' border='0' cellpadding='0' cellspacing='4'><tr><td colspan='2'><input type='radio' id='rttype' checked='checked' value='pub' name='rttype' onclick=\"getRadioSelected('pub','add')\">\u516c\u5171\u6a21\u677f</input><input type='radio' id='rttype' value='pri' name='rttype' onclick=\"getRadioSelected('pri','add')\">\u81ea\u5b9a\u4e49\u6a21\u677f</input><td></tr><tr><td colspan='2'>\u516c\u5171\u6a21\u677f\u5206\u7c7b&nbsp;&nbsp;<select id='addvocMap' name='addvocMap' size='1' style=\"BACKGROUND-COLOR: #d9dcff; COLOR: rgb(0, 0, 128);\" onchange=\"vocSelect('add')\"> </select></td></tr><tr><td  colspan='2' id='rt_table'></td></tr><tr><td  colspan='2' id='dataTable'></td></tr></table>";
	} else {
		rtdiv.innerHTML = "<table id='s' width='100%' border='0' cellpadding='0' cellspacing='4'><tr><td colspan='2'><input type='radio' id='rttype' checked='checked' value='pub' name='rttype' onclick=\"getRadioSelected('pub','up')\">\u516c\u5171\u6a21\u677f</input><input type='radio' id='rttype' value='pri' name='rttype' onclick=\"getRadioSelected('pri','up')\">\u81ea\u5b9a\u4e49\u6a21\u677f</input><td></tr><tr><td colspan='2'>\u516c\u5171\u6a21\u677f\u5206\u7c7b&nbsp;&nbsp;<select id='upvocMap' name='upvocMap' size='1' style=\"BACKGROUND-COLOR: #d9dcff; COLOR: rgb(0, 0, 128);\" onchange=\"vocSelect('up')\"> </select></td></tr><tr><td  colspan='2' id='rt_table'></td></tr><tr><td  colspan='2' id='dataTable'></td></tr></table>";
	}
	DWREngine.setAsync(false);
	getVoc(obj);
	creat_RtDiv_Body(obj);
}
function creat_RtDiv_Prihead(obj) {
	var rtdiv = document.getElementById("rt_div");
	//var rthead = document.getElementById("rt_table");
	if ("add" == obj) {
		rtdiv.innerHTML = "<table id='s' width='100%' border='0' cellpadding='0' cellspacing='4'><tr><td colspan='2'><input type='radio' id='rttype' value='pub' name='rttype' onclick=\"getRadioSelected('pub','add')\">\u516c\u5171\u6a21\u677f</input><input type='radio' id='rttype' value='pri' name='rttype' checked='checked' onclick=\"getRadioSelected('pri','add')\">\u81ea\u5b9a\u4e49\u6a21\u677f</input><td></tr><tr><td  colspan='2' id='rt_table'></td></tr><tr><td  colspan='2' id='dataTable'></td></tr></table>";
	} else {
		rtdiv.innerHTML = "<table id='s' width='100%' border='0' cellpadding='0' cellspacing='4'><tr><td colspan='2'><input type='radio' id='rttype' value='pub' name='rttype' onclick=\"getRadioSelected('pub','up')\">\u516c\u5171\u6a21\u677f</input><input type='radio' id='rttype' value='pri' name='rttype' checked='checked' onclick=\"getRadioSelected('pri','up')\">\u81ea\u5b9a\u4e49\u6a21\u677f</input><td></tr><tr><td  colspan='2' id='rt_table'></td></tr><tr><td  colspan='2' id='dataTable'></td></tr></table>";
	}
	DWREngine.setAsync(false);
	creat_RtDiv_PriBody(obj);
}
function creat_Page(tt, np, obj, type) {
	var page = document.getElementById("page");
	if (isNaN(tt)) {
		tt = parseInt(tt);
	}
	if (isNaN(np)) {
		np = parseInt(np);
	}
	if (null == page) {
		var rt_table = document.getElementById("rt_table");
		rt_table.innerHTML = rt_table.innerHTML + "<table><tr><td colspan='2' id='page'><div><p>\u5171" + tt + "\u9875,\u5f53\u524d\u4e3a\u7b2c" + (np + 1) + "\u9875&nbsp;&nbsp;<a onclick=\"pageGo('" + (np - 1) + "','" + tt + "','" + obj + "','" + type + "')\">\u4e0a\u4e00\u9875</a>&nbsp;&nbsp;<a onclick=\"pageGo('" + (np + 1) + "','" + tt + "','" + obj + "','" + type + "')\">\u4e0b\u4e00\u9875</a>&nbsp;&nbsp;<input type='text' size='3' id='cutpage'/><input type='button' onclick=\"pageGo('','" + tt + "','" + obj + "','" + type + "')\" value='Go'/></p></div></td></tr></table>";
	} else {
		page.innerHTML = "";
		if (np > tt) {
			np = tt - 1;
		}
		page.innerHTML = page.innerHTML + "<div><p>\u5171" + tt + "\u9875,\u5f53\u524d\u4e3a\u7b2c" + (np + 1) + "\u9875&nbsp;&nbsp;<a onclick=\"pageGo('" + (np - 1) + "','" + tt + "','" + obj + "','" + type + "')\">\u4e0a\u4e00\u9875</a>&nbsp;&nbsp;<a onclick=\"pageGo('" + (np + 1) + "','" + tt + "','" + obj + "','" + type + "')\">\u4e0b\u4e00\u9875</a>&nbsp;&nbsp;<input type='text' size='3' id='cutpage'/><input type='button' onclick=\"pageGo('','" + tt + "','" + obj + "','" + type + "')\" value='Go'/></p></div>";
	}
}
function creat_addRtShowTable(ta) {
	var data_table = document.getElementById("dataTables");
	if (null == data_table) {
		var rt_table = document.getElementById("dataTable");
		rt_table.innerHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr><td id='dataTables'></td></tr></table>";
		var data_table = document.getElementById("dataTables");
		data_table.innerHTML ="<table width='100%' bgcolor='#d7d7d7' border='0' cellpadding='0' cellspacing='1'><tr><th bgcolor='#d7d7d7' height='20'>\u7f16\u53f7</th><th bgcolor='#d7d7d7'>\u5185\u5bb9</th></tr>" + ta+"</table>";
	} else {
		data_table.innerHTML = "<table width='100%' bgcolor='#d7d7d7' border='0' cellpadding='0' cellspacing='1'><tr><th bgcolor='#d7d7d7' height='20'>\u7f16\u53f7</th><th bgcolor='#d7d7d7'>\u5185\u5bb9</th></tr>"+ta+"</table>";
	}
}
function creat_upRtShowTable(ta) {
	var data_table = document.getElementById("dataTables");
	if (null == data_table) {
		var rt_table = document.getElementById("dataTable");
		rt_table.innerHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr><td id='dataTables'></td></tr></table>";
		var data_table = document.getElementById("dataTables");
		data_table.innerHTML ="<table width='100%' bgcolor='#d7d7d7' border='0' cellpadding='0' cellspacing='1'><tr><th bgcolor='#d7d7d7' height='20'>\u7f16\u53f7</th><th bgcolor='#d7d7d7'>\u5185\u5bb9</th></tr>" + ta+"</table>";
	} else {
		data_table.innerHTML = "<table width='100%' bgcolor='#d7d7d7' border='0' cellpadding='0' cellspacing='1'><tr><th bgcolor='#d7d7d7' height='20'>\u7f16\u53f7</th><th bgcolor='#d7d7d7'>\u5185\u5bb9</th></tr>"+ta+"</table>";
	}
}
function creat_RtDiv_Body(obj) {
	var vid;
	DWREngine.setAsync(false);
	if ('add' == obj) {
		vid = document.getElementById("addvocMap").value;
		if (null == vid) {
			var vocmap = document.getElementById("addvocMap");
			var index = vocmap.selectedIndex;
			vid = vocmap.options[index].value;
		}
		RtempletDwr.getPuvPage(vid, "0", "0", obj, creat_RtDiv_addBodyData);
	} else {
		vid = document.getElementById("upvocMap").value;
		if (null == vid) {
			var vocmap = document.getElementById("upvocMap");
			var index = vocmap.selectedIndex;
			vid = vocmap.options[index].value;
		}
		RtempletDwr.getPuvPage(vid, "0", "0", obj, creat_RtDiv_upBodyData);
	}
}
function creat_RtDiv_PriBody(obj) {
	if ("add" == obj) {
		RtempletDwr.getRtList("0", "0", obj, creat_RtDiv_addPriBodyData);
	} else {
		RtempletDwr.getRtList("0", "0", obj, creat_RtDiv_upPriBodyData);
	}
}
function creat_RtDiv_addPriBodyData(data) {
	var rt_table = document.getElementById("rt_table");
	if (0 != data.tt) {
		creat_Page(data.tt, data.np, "add", "pri");
	}
	creat_addRtShowTable(data.html);
}
function creat_RtDiv_upPriBodyData(data) {
	var rt_table = document.getElementById("rt_table");
	if (0 != data.tt) {
		creat_Page(data.tt, data.np, "up", "pri");
	}
	creat_addRtShowTable(data.html);
}
function creat_RtDiv_addBodyData(data) {
	var rt_table = document.getElementById("rt_table");
	if (0 != data.tt) {
		creat_Page(data.tt, data.np, "add", "pub");
	}
	creat_addRtShowTable(data.html);
}
function creat_RtDiv_upBodyData(data) {
	var rt_table = document.getElementById("rt_table");
	if (0 != data) {
		creat_Page(data.tt, data.np, "up", "pub");
	}
	creat_upRtShowTable(data.html);
}
function getVoc(obj) {
	if (obj == "add") {
		RtempletDwr.getVocMap(addvocMapRow);
	} else {
		RtempletDwr.getVocMap(upvocMapRow);
	}
}
function addvocMapRow(data) {
	var vid;
	DWRUtil.removeAllOptions("addvocMap");
	DWRUtil.addOptions("addvocMap", data);
	if (null != data) {
		for (var property in data) {
			vid = property;
			break;
		}
	}
	DWRUtil.setValue("addvocMap", vid);
}
function upvocMapRow(data) {
	var vid;
	DWRUtil.removeAllOptions("upvocMap");
	DWRUtil.addOptions("upvocMap", data);
	if (null != data) {
		for (var property in data) {
			vid = property;
			break;
		}
	}
	DWRUtil.setValue("upvocMap", vid);
}
function vocSelect(obj) {
	var vid;
	/**
	if('add'==obj){
		vid = document.getElementById("addvocMap").value;
	}else{
		vid = document.getElementById("addvocMap").value;
	}
	**/
	creat_RtDiv_Body(obj);
}
function pageGo(npage, ttal, obj, type) {
	ttal = parseInt(ttal);
	var cut = document.getElementById("cutpage").value;
	if (null != npage || "" != npage) {
		npage = parseInt(npage);
	}
	if ("" != cut) {
		npage = parseInt(cut);
		if (npage - 1 > 0) {
			npage = npage - 1;
		} else {
			npage = 0;
		}
	}
	if (ttal > npage) {
		if (npage > 0) {
			PageAjax(npage, ttal, obj, type);
		} else {
			PageAjax("0", ttal, obj, type);
		}
	} else {
		PageAjax(ttal - 1, ttal, obj, type);
	}
}
function PageAjax(np, tt, obj, type) {
	var vid;
	if ("pri" == type) {
		if ("add" == obj) {
			RtempletDwr.getRtList(np, tt, obj, creat_RtDiv_addPriBodyData);
		} else {
			RtempletDwr.getRtList(np, tt, obj, creat_RtDiv_upPriBodyData);
		}
	} else {
		if ("add" == obj) {
			vid = document.getElementById("addvocMap").value;
			RtempletDwr.getPuvPage(vid, np, tt, obj, creat_RtDiv_addBodyData);
		} else {
			vid = document.getElementById("upvocMap").value;
			RtempletDwr.getPuvPage(vid, np, tt, obj, creat_RtDiv_upBodyData);
		}
	}
}
function addCont(t) {
	var oEditor = FCKeditorAPI.GetInstance("addcont");
	oEditor.InsertHtml(t.innerHTML);
	closelistDiv1('plmb');
	//document.getElementById("plmb").style.display='none';
	//document.getElementById('float_bg1').style.display='none';
}
function upCont(t) {
	var oEditor = FCKeditorAPI.GetInstance("upcont");
	oEditor.InsertHtml(t.innerHTML);
	//document.getElementById("plmb").style.display='none';
	//document.getElementById('float_bg1').style.display='none';
	closelistDiv1('plmb');
}


function selectTComments(id) {
	RtempletDwr.getTeacherComments(id, getTComInfo);
}


function getTComInfo(data) {
	document.getElementById("uptitle").value = data.title;
	document.getElementById("uppyid").value = data.sendCommentId;
	document.getElementById("upstuid").value = data.studentId;
	document.getElementById("uptime").value = data.time;
	FCKeditorAPI.GetInstance("upcont").EditorDocument.body.innerHTML = data.content;
}

//get updateRtemplet info
function getRtemplet(id){
	RtempletDwr.getRtempletInfo(id,updateRt);
}
function updateRt(data){
	if(null!=data){
		document.getElementById("uprttitle").value=data.title;
		FCKeditorAPI.GetInstance("upcont").EditorDocument.body.innerHTML = data.content;
		document.getElementById("upmbid").value = data.modeid;
	}else{
		alert("\u51fa\u9519\uff0c\u8bf7\u5237\u65b0\u540e\u91cd\u8bd5");
	}
}
